package com.xyh.run.utils;

import com.alibaba.fastjson.JSON;
import com.alibaba.fastjson.JSONObject;
import org.apache.ibatis.jdbc.SQL;

import java.io.*;
import java.util.Base64;
import java.util.UUID;

/**
 * @version v1.0
 * @类描述：
 * @项目名称：
 * @包名： com.xu.test
 * @类名称：main
 * @创建人：YIHANG.XU
 * @创建时间：2022/1/17:30 下午
 * @修改人：YIHANG.XU
 * @修改时间：2022/1/17:30 下午
 * @修改备注：
 * @Copyright
 */
public class main {
    public static void main(String[] args) throws Exception {
         getFileValue();

    }

    public static String getFileValue() throws Exception {
        File file = new File("/Users/xuyihang/Desktop/spring.log");
        InputStreamReader inputStreamReader = new InputStreamReader(new FileInputStream(file));
        BufferedReader br = new BufferedReader(inputStreamReader);
        StringBuilder result = new StringBuilder();
        String faceId = "";
        String s = null;
        while ((s = br.readLine()) != null) {
            if (s.contains("请求数据:")) {
                String substring2 = s.substring(36, 54);
                int i = s.indexOf("请求数据:") + 5;
                String substring = s.substring(i);
                JSONObject jsonObject = JSON.parseObject(substring);
                String imageData = jsonObject.getString("imageData");

                int i1 = imageData.indexOf("proxy?") + 8;
                String substring1 = imageData.substring(i1);
                byte[] decode = Base64.getDecoder().decode(substring1);
                String face = new String(decode);

                String faceid = face.substring((face.indexOf("=") + 1));
                faceId = faceid;



            }else if(s.contains("返回数据:")){
                String substring2 = s.substring(36, 54);

                String substring = s.substring(0, 19);
                String sql =" update helmet_record_request set updateTime = '"+substring+"' where imageId1400 ='"+faceId+"';";
                System.out.println(sql);
            }


        }
        String value = result.toString();
        br.close();
        //file.delete();
        return value;
    }

    // 记录内容到文件
    public static void writeStringToFile(byte[] imageByte, String filePath, String fileName) throws Exception {
        OutputStream out = new FileOutputStream(filePath + fileName);
        out.write(imageByte);
        out.flush();
        out.close();


    }

}
